﻿#ifndef CARD_H
#define CARD_H

#include <QGraphicsObject>
#include <QGraphicsScene>
#include <QPixmap>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>

class GameManager;
class GameManagerOnline;
class GameWin;

class Card : public QGraphicsObject
{
    Q_OBJECT
public:
    enum Group{
        BLUE,
        RED,
        DEAD
    };

    enum Monster_Type{ // NU表示该卡槽位置已被抹除(吃掉)了
        NU,
        RAT,
        CAT,
        DOG,
        WOLF,
        CHEETAH,
        LION,
        TIGER,
        ELEPHANT
    };

public:
    Card(QGraphicsScene* scene, QString face, Group group, Monster_Type type);
    ~Card();

public:
    QRectF boundingRect() const;  // 重写绘图区域
    bool checkColliding();
    void setIsBack(bool para);

protected:
    void paint(QPainter *painter,
          const QStyleOptionGraphicsItem *option,
          QWidget *widget);
    void mousePressEvent(QGraphicsSceneMouseEvent *event = nullptr);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    void keyPressEvent(QKeyEvent *event);

private:
    // 初始化动画
    void initAnimation();
    void drawFace(QString strFace);

    // 四个方向的移动动画
    void upAnimation();
    void downAnimation();
    void leftAnimation();
    void rightAnimation();

    // 翻面动画
    void openAnimation();



private:
    QGraphicsScene* m_scene;
    bool m_isBack; // 卡牌受否在背面
    bool m_isSelect; // 卡牌是否被选中
    bool m_isStadingBy; // 开牌是否准备行动
    QPixmap* m_face;
    Group m_group; // 阵营 true为红色 false为蓝色
    QPoint m_destion; // 目的地坐标
    Monster_Type m_type; // 卡牌物种
    bool m_upAllow;
    bool m_downAllow;
    bool m_leftAllow;
    bool m_rightAllow;

    QPropertyAnimation* m_upAnimations; // 四向移动动画
    QPropertyAnimation* m_downAnimations;
    QPropertyAnimation* m_leftAnimations;
    QPropertyAnimation* m_rightAnimations;

    QPropertyAnimation* m_rotAnimation;
    QPropertyAnimation* m_fadeAnimation;
    QPropertyAnimation* m_openAnimation;
    QSequentialAnimationGroup* Card_Select;
    QSequentialAnimationGroup* Card_Open;

    friend class GameManager; // 声明友元类
    friend class GameManagerOnline;
    friend class GameWin;

signals:
    void cardDO(bool m_group, int moveRotation, Card* cards);

};

#endif // CARD_H
